"use strict";

// 依赖jq，需要后于jq引入
$(document).ready(function() {
  var i = 1;
  var me = parent.layer.getFrameIndex(window.name); // 获取窗口索引
  document.getElementById("add_new").addEventListener("click", function() {
    if (document.getElementById("mulit").lastElementChild.value.length === 0) {
      alert("请先填写所有空渠道。");
      return false;
    }
    var type = document.getElementById("qudao").cloneNode(true);
    var brEle = document.createElement("br");
    type.value = "";
    type.id = type.id + "_" + i++;
    document.getElementById("mulit").appendChild(brEle);
    document.getElementById("mulit").appendChild(type);
  });
  document.getElementById("yes").addEventListener("click", function() {
    var formData = $("#main_form").serializeArray();
    var name = document.getElementById("chanpin_name").value;
    if (name.length > 0) {
      var ele = document.createElement("br");
      parent.$("#simple_table").append(ele);
    } else {
      alert("请填写名称");
    }
  });
  document.getElementById("no").addEventListener("click", function() {
    parent.layer.close(me);
  });
});
